<%--
  Created by IntelliJ IDEA.
  User: zhangdeng
  Date: 2020/12/02
  Time: 10:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.sjsq.po.User" %>
<%@ page import="com.sjsq.po.Card" %>
<%@ page import="com.sjsq.service.CardService" %>
<%@ page import="com.sjsq.service.impl.CardServiceImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="com.sjsq.dao.BookDao" %>
<%@ page import="com.sjsq.dao.impl.BookDaoImpl" %>
<html>
<head>
    <title>购物车信息</title>
    <style type="text/css">
        h1{
            text-align: center;
        }
        #before{
            text-align: center;
        }
        #head{
            background: #eeeeee;height: 80px;
        }
        #headLink{
            font-size: 20px;
        }
        #headWelLink{
            font-size: 20px;
        }
    </style>
</head>
<body>
    <%--头部信息--%>
    <%
        User user =(User)session.getAttribute("user");
        if(user == null){
            response.sendRedirect("login.jsp");
        }else {
    %>
    <div id="head">
        <table width="100%">
            <td id="headWelLink">欢迎您：<%=user.getName()%></td>
            <td align="right" id="headLink">
                <a href="cart.jsp">我的购物车</a>
                <a href="logout.jsp">安全退出</a>
            </td>
        </table>
    </div>
    <%
        }
    %>

    <%--图书信息--%>
    <%
        CardService service = new CardServiceImpl();
        List<Card> list = service.getCard(user.getId());
        BookDao dao = new BookDaoImpl();
        Double totalPrice = 0D;
        Double bookPrice = 0D;
    %>
    <h1>购物车图书</h1>
    <div id="before">
        <a href="javascript: window.history.go(-1)">返回上一级</a>
    </div>
    <table align="center" cellpadding="10" cellspacing="10">
        <tr bgcolor="green">
            <td>姓名</td>
            <td>图书序号</td>
            <td>书名</td>
            <td>数量</td>
            <td>价格小计</td>
        </tr>
        <%
            for (int i = 0;i<list.size();i++){
            Card card = list.get(i);
            String bookName = dao.getBook(card.getBookid()).getBookname();
            bookPrice = dao.getBook(card.getBookid()).getPrice()*card.getBooknum();
            totalPrice = bookPrice + totalPrice;
        %>
        <tr bgcolor="#ffdead">
            <td><%=card.getUsername() %></td>
            <td><%=card.getBookid() %></td>
            <td><%=bookName %></td>
            <td><%=card.getBooknum() %></td>
            <td><%=bookPrice%></td>
        </tr>
        <%
            }
        %>
        <tr>
            <td colspan="4" align="right" bgcolor="#6495ed">价格总计</td>
            <td bgcolor="#6495ed"><%=totalPrice %></td>
        </tr>
    </table>
    <div style="text-align:center;font-size:20px;margin-top:20px;">
        <a href="book.jsp">继续购买图书</a>
        <a href="login.jsp">登陆页面</a>
    </div>
</body>
</html>
